/*********************************************************************************
 *      Copyright:  (C) 2022 xiezongyi<1764417007@qq.com>
 *                  All rights reserved.
 *
 *       Filename:  thread_init.c
 *    Description:  This file 
 *                 
 *        Version:  1.0.0(13/05/22)
 *         Author:  xiezongyi <1764417007@qq.com>
 *      ChangeLog:  1, Release initial version on "13/05/22 15:16:54"
 *                 
 ********************************************************************************/

#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <pthread.h>


//对线程进行初始化、设置栈的大小、设置线程的分离状态
int thread_init(pthread_attr_t *thread_attr)
{

    if(pthread_attr_init(thread_attr))
    {
        printf("pthread_attr_init() failure: %s\n", strerror(errno));
        return -1;
    }

    if(pthread_attr_setstacksize(thread_attr, 512*1024))
    {
        printf("pthread_attr_setstacksize() failure: %s\n", strerror(errno));
        return -2;
    }

    if(pthread_attr_setdetachstate(thread_attr, PTHREAD_CREATE_DETACHED))
    {
        printf("pthread_attr_setdetachstate() failure: %s\n", strerror(errno));
        return -3;
    }

    return 0;
}

